/*
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-05-19 09:52:03
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-05-28 17:40:04
 * @FilePath: /XMate-h5/src/utils/yxtToast.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { showLoadingToast, closeToast } from "vant";

let timer;

export const yxtShowLoading = (op, timeout = 0) => {
  const toast = showLoadingToast({
    ...op
  });
  if (timeout <= 0) return;

  let second = timeout;
  const { message } = op;
  clearInterval(timer);
  timer = setInterval(() => {
    second--;
    if (second > 0) {
      // 是否展示倒计时
      let showTime = second <= timeout - 5;
      toast.message = `${message}${showTime ? "(" + second + ")" : ""}`;
    } else {
      clearInterval(timer);
      closeToast();
    }
  }, 1000);
};
